﻿// <copyright file="BitmapUtils.cs" company="Embedded Media Framework">
// Published unter MS-PL at http://www.codeplex.com/emf
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Ulrich 'connex' Strauss</author>
// <email>http://www.codeplex.com/emf/</email>
// <date>2008-11-13</date>

using System;
using System.Drawing;

namespace EMF.Core.Utils
{
    /// <summary>
    /// A Helper Class for Bitmaps
    /// </summary>
    public static class BitmapUtils 
    {
        /// <summary>
        /// Converts an <see cref="System.Drawing.Icon"/> to a <see cref="System.Drawing.Bitmap"/>.
        /// </summary>
        /// <param name="icon">The icon.</param>
        /// <returns>The converted Icon as Bitmap</returns>
        public static Bitmap IconToBitmap(Icon icon)          
        {
            Bitmap bmp = new Bitmap(icon.Width, icon.Height);
            using (Graphics gxMem = Graphics.FromImage(bmp))
            {
                // Draw the icon
                gxMem.DrawIcon(icon, 0, 0);
            }

            return bmp;
        }
    }
}
